﻿package com.hxh.ocean.view {
	
	import flash.events.*;
	import flash.utils.Timer;
	import flash.display.MovieClip;
	import hxh.ocean.events.*
	import com.hxh.utils.*;
	
	public class MenuChildItem extends Bubble{
	
		private var _popTimer:Timer;
		private var _parentItem:MenuItem;
		private var _isAlive:Boolean;
		
		// Initialization:
		public function MenuChildItem(childItemName:String, url:String=null) {
			var sprite:MovieClip = new BubbleView();
			super(childItemName, sprite);
			_moveSpeed = 0;
			TargetURL = url;
			_isAlive = false;
		}
		
		public function set ParentItem(item:MenuItem):void{
			_parentItem = item;
		}
		
		public function get ParentItem():MenuItem{
			return _parentItem;
		}
		
		public function set IsAlive(bool:Boolean):void{
			_isAlive = bool;
		}
		
		public function get IsAlive():Boolean{
			return _isAlive;
		}
		
		protected override function doUpdate():void{
			//Need to empty this method since the child item doesn't
			//need to update itself
		}
		
		public override function popIn():void{
			visible = false;
			_popTimer = new Timer(Maths.randomInt(0,500),1);
			_popTimer.start();
			_popTimer.addEventListener(TimerEvent.TIMER_COMPLETE, popInNow);
		}
		
		public override function popOut():void{
			_popTimer = new Timer(Maths.randomInt(0,500),1);
			_popTimer.start();
			_popTimer.addEventListener(TimerEvent.TIMER_COMPLETE, popOutNow);
		}
		
		protected override function mouseIn(evt:MouseEvent):void{
			super.mouseIn(evt);
			dispatchEvent(new Event(Events.CHILDITEM_OVER));
		}
		
		protected override function mouseAway(evt:MouseEvent):void{
			super.mouseAway(evt);
			dispatchEvent(new Event(Events.CHILDITEM_OUT));
		}
		
		private function popInNow(evt:TimerEvent):void{
			visible = true;
			super.popIn();
			_isAlive = true;
		}
		
		private function popOutNow(evt:TimerEvent):void{
			super.popOut();
		}
	}
}